import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:myapp/common_ui/web/webview_widget.dart';
import 'package:myapp/pages/about_us/about_us_page.dart';
import 'package:myapp/pages/auth/login_page.dart';
import 'package:myapp/pages/auth/register_page.dart';
import 'package:myapp/pages/home/home_page.dart';
import 'package:myapp/pages/knowledge/detail/knowledge_detail_tab_page.dart';
import 'package:myapp/pages/my_collects/my_collects_page.dart';
import 'package:myapp/pages/search/search_page.dart';
import 'package:myapp/pages/tab_page.dart';
import 'package:myapp/pages/web_view_page.dart';

import '../common_ui/web/webview_page.dart';


///路由管理类
class Routes {
  static Route<dynamic> generateRoute(RouteSettings settings) {
    switch (settings.name) {
      //首页
      case RoutePath.tab:
        return pageRoute(TabPage(),settings:settings);
      //知识体系明细页面
      case RoutePath.detailKnowledgePage:
        return pageRoute(KnowledgeDetailTabPage(),settings:settings);
      //登录
      case RoutePath.loginPage:
        return pageRoute(LoginPage(),settings:settings);
      //注册
      case RoutePath.registerPage:
        return pageRoute(RegisterPage(),settings:settings);
      //我的收藏页面
      case RoutePath.my_collects:
        return pageRoute(MyCollectsPage(),settings:settings);
      //显示网页资源的页面
      case RoutePath.webViewPage:
        return pageRoute(WebViewPage(loadResource: "",webViewType: WebViewType.URL,),settings:settings);
      //关于我们
      case RoutePath.about_us:
        return pageRoute(AboutUsPage(),settings:settings);
      //搜索页
      case RoutePath.searchPage:
        return pageRoute(SearchPage(),settings:settings);
    }
    return pageRoute(
      Scaffold(
        body: SafeArea(child: Center(child: Text("路由:  ${settings.name} 不存在"))),
      ),
    );
  }

  static MaterialPageRoute pageRoute(
    Widget page, {
    RouteSettings? settings,
    bool? fullscreenDialog,
    bool? maintainState,
    bool? allowSnapshotting,
  }) {
    return MaterialPageRoute(
      builder: (context) {
        return page;
      },
      settings: settings,
      fullscreenDialog: fullscreenDialog ?? false,
      maintainState: maintainState ?? true,
      allowSnapshotting: allowSnapshotting ?? true,
    );
  }
}

///路由地址
class RoutePath {
  //首页
  static const String tab = "/";

  ///网页页面
  static const String webViewPage = "/web_view_page";

  ///登录页面
  static const String loginPage = "/login_page";
  ///注册页面
  static const String registerPage = "/register_page";

  //知识体系明细
  static const String detailKnowledgePage = "/detail_knowledge_page";
  ///搜索页
  static const String searchPage = "/search_page";

  //我的收藏页面
  static const String my_collects = "/my_collects";

  //关于我们
  static const String about_us = "/about_us";
}
